# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  skip_before_filter :verify_authenticity_token 
  helper :all # include all helpers, all the time

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery :except => [:auto_complete_for_user_ident]
  # :secret => '9806b8bab22010bcbdf8f4da126c1c6e'
  
  # See ActionController::Base for details 
  # Uncomment this to filter the contents of submitted sensitive data parameters
  # from your application log (in this case, all fields with names like "password"). 
  # filter_parameter_logging :password
  def login_required
    if session[:user]
      return true
    end
    flash[:warning]="Please login"
    session[:return_to]=request.request_uri
    redirect_to :controller => "user",:action=>"login"
    return false
  end

  def current_user
    session[:user]
  end

  def redirect_to_stored
    if session[:return_to].nil?
      redirect_to :controller =>'user', :action => 'home'
    else
      ret=session[:return_to]
      session[:return_to]=nil
      redirect_to :uri=>ret
    end
  end

end
